<?php

namespace app\api\controller\ykjp\information\basisinfo;
use app\common\controller\Api;

/**
 * 供应商管理
 *
 * @icon fa fa-circle-o
 */
class Supplier extends Api
{

    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = '*';


    /**
     * 查看
     */
    public function index()
    {
        $this->model = new \app\admin\model\ykjp\information\basisinfo\Supplier;
        $row = $this->model->where('deletetime',null)->select();
        $this->success('返回成功', ['data' => $row]);
    }

    
    /**
     * 查看详情
     */
    public function getdetails()
    {
        $id = input('post.id');
        $this->model = new \app\admin\model\ykjp\information\basisinfo\Supplier;
        $row = $this->model->where('id',$id)->select();
        $this->success('返回成功', ['data' => $row]);
    }

    public function deleteProduct()
    {
        $id = input('post.id');
        $row = \app\admin\model\ykjp\information\basisinfo\Supplier::where("id", $id)->delete();
        $this->success('返回成功', ['data' =>'删除成功！']);
    }


    /**
     *获取业务员
     */
     public function getsalesman(){
        $this->dataLimit=false;
        $result=array("rows"=>[],"total"=>0);
        if ($this->request->isAjax()) {
           $this->model=model("admin");
           return parent::selectpage();
         }
         return json($result);
    }
    
    /**
     * 删除
     */

    public function add(){
        $name = input('post.name');
        $contact = input('post.contact');
        $address = input('post.address');
        $city = input('post.city');
        $description = input('post.description');
        $phone = input('post.phone');
        $term = input('post.term');

        $model = new \app\admin\model\ykjp\information\basisinfo\Supplier;
        $code="SP".date("YmdHis",time());
        $time = time();

        $model->insert([
            'name' => $name,
            'contact' => $contact,
            'address' => $address,
            'city' => $city,
            'description' => $description,
            'phone' => $phone,
            'term' => $term,
            'code' => $code,
            'createtime' => $time,
            'updatetime' => $time
        ]);
        

        $this->success('返回成功', ['data' =>'添加成功！']);
    }
}
